package com.ruoyi.profession.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.profession.domain.Patents;
import com.ruoyi.profession.service.IPatentsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 专利信息Controller
 * 
 * @author 靳双伟
 * @date 2024-06-01
 */
@RestController
@RequestMapping("/profession/patents")
public class PatentsController extends BaseController
{
    @Autowired
    private IPatentsService patentsService;

    /**
     * 查询专利信息列表
     */
    @PreAuthorize("@ss.hasPermi('profession:patents:list')")
    @GetMapping("/list")
    public TableDataInfo list(Patents patents)
    {
        startPage();
        List<Patents> list = patentsService.selectPatentsList(patents);
        return getDataTable(list);
    }

    /**
     * 导出专利信息列表
     */
    @PreAuthorize("@ss.hasPermi('profession:patents:export')")
    @Log(title = "专利信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Patents patents)
    {
        List<Patents> list = patentsService.selectPatentsList(patents);
        ExcelUtil<Patents> util = new ExcelUtil<Patents>(Patents.class);
        util.exportExcel(response, list, "专利信息数据");
    }

    /**
     * 获取专利信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('profession:patents:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(patentsService.selectPatentsById(id));
    }

    /**
     * 新增专利信息
     */
    @PreAuthorize("@ss.hasPermi('profession:patents:add')")
    @Log(title = "专利信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Patents patents)
    {
        return toAjax(patentsService.insertPatents(patents));
    }

    /**
     * 修改专利信息
     */
    @PreAuthorize("@ss.hasPermi('profession:patents:edit')")
    @Log(title = "专利信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Patents patents)
    {
        return toAjax(patentsService.updatePatents(patents));
    }

    /**
     * 删除专利信息
     */
    @PreAuthorize("@ss.hasPermi('profession:patents:remove')")
    @Log(title = "专利信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(patentsService.deletePatentsByIds(ids));
    }
}
